import { Character, CharacterElement, CharacterExtend, CharacterPath } from "shared/api/character/type";
import fetchApi from "shared/api/strapi";

export class CharacterApi {
  static getCharacterList = ({ query }: { query?: Record<string, string> }) => {
    return fetchApi<Character[]>({
      endpoint: "characters",
      query: {
        populate: "icon",
        "sort[0]": "name",
        "pagination[pageSize]": "100",
        ...query,
      },
      wrappedByKey: "data",
      options: {
        tags: ["character"],
      },
    });
  };

  static getCharacter = (slug: string) => {
    return fetchApi<CharacterExtend>({
      endpoint: "characters",
      query: {
        "filters[slug][$eq]": slug,
        "populate[0]": "info",
        "populate[1]": "info.main_skill,info.eidolon,info.eidolon.image,info.image,info.meta_img",
        "populate[2]": "info.main_skill.icon",
      },
      wrappedByKey: "data",
      wrappedByList: true,
      options: {
        tags: ["character"],
      },
    });
  };
}
